home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacWT 0.9 / wt Mac Source / ShowHideMenubar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-28  |  2.3 KB  |  107 lines  |  [TEXT/CWIE]

  1. /*
  2. ** File:        ShowHideMenubar.c
  3. **
  4. ** Written by:    Bill Hayden
  5. **                Nikol Software
  6. **
  7. ** Copyright © 1995 Nikol Software
  8. ** All rights reserved.
  9. **
  10. **
  11. ** Based on code by:
  12. ** David Hayward, Developer Technical Support
  13. ** AppleLink: DEVSUPPORT
  14. */
  15.  
  16.  
  17. #include <QuickDraw.h>
  18. #include <LowMem.h>
  19.  
  20. #include "ShowHideMenubar.h"
  21.  
  22.  
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27.  
  28. short            gOldBarHgt = 20;
  29. short            gMBarState = SHOW;
  30. RgnHandle        mBarRgn;
  31.  
  32.  
  33. static void GetMBarRgn ( RgnHandle mBarRgn ) ;
  34.  
  35.  
  36.  
  37. /*****************************************************************************/
  38.  
  39.  
  40.  
  41. // changes the menubar state (vis) to either SHOW or HIDE, with obvious results
  42.  
  43. void SetMBarState (char vis)
  44. {
  45.     static short    first = true;
  46.     RgnHandle        GrayRgn = LMGetGrayRgn();
  47.     
  48.     if (first)                                /* if its the 1st time called */
  49.         {
  50.         gOldBarHgt = GetMBarHeight();        /* remember the bar height */
  51.         first = false;
  52.         }
  53.     
  54.     if (vis == gMBarState)                    /* return if nothing would change */
  55.         return;
  56.         
  57.     if (!vis)                                /* if HIDE */
  58.         {
  59.         WindowRef    wpFirst = LMGetWindowList();
  60.  
  61.         LMSetMBarHeight(0);                    /* make the Menu Bar's height zero */
  62.         
  63.         mBarRgn = NewRgn();
  64.         GetMBarRgn(mBarRgn);                /* make a region for the mbar */
  65.         UnionRgn(GrayRgn,mBarRgn,GrayRgn);    /* tell the desktop it covers the menu bar */
  66.     
  67.         PaintBehind(wpFirst, mBarRgn);        /* redraw windows behind front */    
  68.         CalcVisBehind(wpFirst, mBarRgn);    /* redraw windows behind front */    
  69.         }
  70.     else                                    /* if SHOW */
  71.         {
  72.         LMSetMBarHeight(gOldBarHgt);        /* make the menu bar's height normal */
  73.         
  74.         DiffRgn(GrayRgn, mBarRgn, GrayRgn);    /* remove the menu bar from the desktop  */
  75.         DisposeRgn(mBarRgn);                /* dispose to the bar region */
  76.         
  77.         DrawMenuBar();                        /* redraw the menu bar */
  78.         }
  79.     gMBarState = !gMBarState;                /* toggle the state */
  80. }
  81.  
  82.  
  83.  
  84. //an accessor to allow others to read private gMBarState global
  85.  
  86. char GetMBarState (void)
  87. {
  88.     return gMBarState;
  89. }
  90.  
  91.  
  92.  
  93.  
  94. // uses globals to calculate the region for the MenuBar
  95. // the RgnHandle mBarRgn must be allocated with NewRgn() before calling
  96.  
  97. static void GetMBarRgn (RgnHandle mBarRgn)
  98. {
  99.     Rect            mBarRect;
  100.  
  101.     mBarRect = qd.screenBits.bounds;            /* create a rect for the mbar */
  102.     mBarRect.bottom = mBarRect.top + gOldBarHgt;
  103.     RectRgn(mBarRgn, &mBarRect);                /* make a region for the mbar */
  104. }
  105.  
  106.  
  107.